//
//  SelectedFunctionView.m
//  PywSDK_Demo
//
//  Created by smallwave on 16/9/8.
//  Copyright © 2016年 pengyouwan. All rights reserved.
//

#import "SelectedFunctionView.h"
#import "ZXPAutoLayout.h"

@interface SelectedFunctionView ()

/**
 注销
 */
@property (nonatomic, strong) UIButton      *logoutBtn;

/**
 用户中心
 */
@property (nonatomic, strong) UIButton      *centerBtn;

/**
 支付
 */
@property (nonatomic, strong) UIButton      *payBtn;

/**
 商品ID
 */
@property (nonatomic, strong) UILabel       *cpIdLabel;
@property (nonatomic, strong) UITextField   *cpIdText;

/**
 商品价格
 */
@property (nonatomic, strong) UILabel       *priceLabel;
@property (nonatomic, strong) UITextField   *priceText;

/**
 充值类型
 */
@property (nonatomic, strong) UILabel       *payTypeLabel;
@property (nonatomic, strong) UITextField   *payTypeText;

/**
 游戏角色
 */
@property (nonatomic, strong) UILabel       *rolenameLabel;
@property (nonatomic, strong) UITextField   *rolenameText;

/**
 游戏区服
 */
@property (nonatomic, strong) UILabel       *serviceLabel;
@property (nonatomic, strong) UITextField   *serviceText;

@end

@implementation SelectedFunctionView

- (instancetype)initWithDelegate:(id<PywPasswordViewDelegate>)delegate{
    self = [super init];
    if (self) {
        self.delegate = delegate;
        [self prepareUI];
    }
    return self;
}
- (void)prepareUI{
    [self addSubview:self.payBtn];
    
    [self addSubview:self.cpIdLabel];
    [self addSubview:self.cpIdText];
    
    [self addSubview:self.priceLabel];
    [self addSubview:self.priceText];
    
    [self addSubview:self.payTypeLabel];
    [self addSubview:self.payTypeText];
    
    [self addSubview:self.rolenameLabel];
    [self addSubview:self.rolenameText];
    
    [self addSubview:self.serviceLabel];
    [self addSubview:self.serviceText];
    
    [self addSubview:self.centerBtn];
    [self addSubview:self.logoutBtn];
    
    __weak typeof(self) wSelf = self;
    // 固定支付
    [wSelf.payBtn zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpace(10).leftSpace(0);
        layout.widthValue(120);
        layout.heightValue(30);
    }];
    // 充值类型
    [wSelf.payTypeLabel zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.payBtn,5);
        layout.leftSpaceEqualTo(wSelf.payBtn,0);
        layout.widthEqualTo(wSelf.payBtn,0).multiplier(0.8);
        layout.heightEqualTo(wSelf.payBtn,0);
    }];
    [wSelf.payTypeText zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.payBtn,5);
        layout.leftSpaceByView(wSelf.cpIdLabel,10);
        layout.rightSpaceEqualTo(wSelf,0);
        layout.heightEqualTo(wSelf.payBtn,0);
    }];
    // 商品ID
    [wSelf.cpIdLabel zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.payTypeLabel,5);
        layout.leftSpaceEqualTo(wSelf.payBtn,0);
        layout.widthEqualTo(wSelf.payBtn,0).multiplier(0.8);
        layout.heightEqualTo(wSelf.payBtn,0);
    }];
    [wSelf.cpIdText zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.payTypeLabel,5);
        layout.leftSpaceByView(wSelf.cpIdLabel,10);
        layout.rightSpaceEqualTo(wSelf,0);
        layout.heightEqualTo(wSelf.payBtn,0);
    }];
    // 价格
    [wSelf.priceLabel zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.cpIdLabel,5);
        layout.leftSpaceEqualTo(wSelf.cpIdLabel,0);
        layout.widthEqualTo(wSelf.cpIdLabel,0);
        layout.heightEqualTo(wSelf.cpIdLabel,0);
    }];
    [wSelf.priceText zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.cpIdText,5);
        layout.rightSpaceEqualTo(wSelf.cpIdText,0);
        layout.widthEqualTo(wSelf.cpIdText,0);
        layout.heightEqualTo(wSelf.cpIdText,0);
    }];
    // 游戏角色
    [wSelf.rolenameLabel zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.priceLabel,5);
        layout.leftSpaceEqualTo(wSelf.priceLabel,0);
        layout.widthEqualTo(wSelf.priceLabel,0);
        layout.heightEqualTo(wSelf.priceLabel,0);
    }];
    [wSelf.rolenameText zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.priceText,5);
        layout.rightSpaceEqualTo(wSelf.priceText,0);
        layout.widthEqualTo(wSelf.priceText,0);
        layout.heightEqualTo(wSelf.priceText,0);
    }];
    // 游戏区服
    [wSelf.serviceLabel zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.rolenameLabel,5);
        layout.leftSpaceEqualTo(wSelf.rolenameLabel,0);
        layout.widthEqualTo(wSelf.rolenameLabel,0);
        layout.heightEqualTo(wSelf.rolenameLabel,0);
    }];
    [wSelf.serviceText zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.rolenameText,5);
        layout.rightSpaceEqualTo(wSelf.rolenameText,0);
        layout.widthEqualTo(wSelf.rolenameText,0);
        layout.heightEqualTo(wSelf.rolenameText,0);
    }];
    // 用户中心
    [wSelf.centerBtn zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.serviceLabel,5);
        layout.leftSpaceEqualTo(wSelf.payBtn,0);
        layout.widthEqualTo(wSelf.payBtn,0).heightEqualTo(wSelf.payBtn,0);
    }];
    // 注销用户
    [wSelf.logoutBtn zxp_addConstraints:^(ZXPAutoLayoutMaker *layout) {
        layout.topSpaceByView(wSelf.serviceLabel,5);
        layout.leftSpaceByView(wSelf.centerBtn, 20);
        layout.widthEqualTo(wSelf.centerBtn,0).heightEqualTo(wSelf.centerBtn,0);
    }];
}
#pragma mark - action
- (void)action:(UIButton *)btn{
    [self endEditing:YES];
    
    if ([self.delegate respondsToSelector:@selector(selectedFunctionView:selectedButton:)]) {
        [self.delegate selectedFunctionView:self selectedButton:btn];
    }
}
#pragma mark - Lazy
// 充值
- (UIButton *)payBtn{
    if (!_payBtn) {
        _payBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _payBtn.backgroundColor = [UIColor orangeColor];
        _payBtn.layer.cornerRadius = 5;
        _payBtn.tag = 100;
        [_payBtn setTitle:@"游戏充值" forState:UIControlStateNormal];
        [_payBtn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
        [_payBtn addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _payBtn;
}

// 充值类型
- (UILabel *)payTypeLabel{
    if (!_payTypeLabel) {
        _payTypeLabel = [UILabel new];
        _payTypeLabel.backgroundColor = [UIColor orangeColor];
        _payTypeLabel.textColor = [UIColor whiteColor];
        _payTypeLabel.layer.cornerRadius = 5;
        _payTypeLabel.layer.masksToBounds = YES;
        _payTypeLabel.font = [UIFont systemFontOfSize:14];
        _payTypeLabel.textAlignment = NSTextAlignmentCenter;
        _payTypeLabel.text = @"充值类型:";
    }
    return _payTypeLabel;
}
- (UITextField *)payTypeText{
    if (!_payTypeText) {
        _payTypeText = [UITextField new];
        _payTypeText.backgroundColor = [UIColor whiteColor];
        _payTypeText.font = [UIFont systemFontOfSize:12];
        _payTypeText.clearButtonMode = UITextFieldViewModeWhileEditing;
        _payTypeText.placeholder = @"请输入充值类型（1：固定支付，2：任意支付）";
        _payTypeText.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _payTypeText.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _payTypeText.layer.borderWidth = 1;
        _payTypeText.layer.cornerRadius = 5;
        _payTypeText.layer.masksToBounds = YES;
        _payTypeText.textAlignment = NSTextAlignmentCenter;
        _payTypeText.clearButtonMode = UITextFieldViewModeWhileEditing;
        _payTypeText.text = @"2";
    }
    return _payTypeText;
}


// 商品ID
- (UILabel *)cpIdLabel{
    if (!_cpIdLabel) {
        _cpIdLabel = [UILabel new];
        _cpIdLabel.backgroundColor = [UIColor orangeColor];
        _cpIdLabel.textColor = [UIColor whiteColor];
        _cpIdLabel.layer.cornerRadius = 5;
        _cpIdLabel.layer.masksToBounds = YES;
        _cpIdLabel.font = [UIFont systemFontOfSize:14];
        _cpIdLabel.textAlignment = NSTextAlignmentCenter;
        _cpIdLabel.text = @"商品ID:";
    }
    return _cpIdLabel;
}
- (UITextField *)cpIdText{
    if (!_cpIdText) {
        _cpIdText = [UITextField new];
        _cpIdText.backgroundColor = [UIColor whiteColor];
        _cpIdText.font = [UIFont systemFontOfSize:12];
        _cpIdText.clearButtonMode = UITextFieldViewModeWhileEditing;
        _cpIdText.placeholder = @"请输入’定额支付‘商品ID";
        _cpIdText.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _cpIdText.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _cpIdText.layer.borderWidth = 1;
        _cpIdText.layer.cornerRadius = 5;
        _cpIdText.layer.masksToBounds = YES;
        _cpIdText.textAlignment = NSTextAlignmentCenter;
        _cpIdText.clearButtonMode = UITextFieldViewModeWhileEditing;
        _cpIdText.text = @"1"; // com.pywsdk.test.01
    }
    return _cpIdText;
}
// 价格
- (UILabel *)priceLabel{
    if (!_priceLabel) {
        _priceLabel = [UILabel new];
        _priceLabel.backgroundColor = [UIColor orangeColor];
        _priceLabel.textColor = [UIColor whiteColor];
        _priceLabel.layer.cornerRadius = 5;
        _priceLabel.layer.masksToBounds = YES;
        _priceLabel.font = [UIFont systemFontOfSize:14];
        _priceLabel.textAlignment = NSTextAlignmentCenter;
        _priceLabel.text = @"价   格:";
    }
    return _priceLabel;
}
- (UITextField *)priceText{
    if (!_priceText) {
        _priceText = [UITextField new];
        _priceText.backgroundColor = [UIColor whiteColor];
        _priceText.font = [UIFont systemFontOfSize:12];
        _priceText.clearButtonMode = UITextFieldViewModeWhileEditing;
        _priceText.placeholder = @"请输入商品价格";
        _priceText.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _priceText.layer.borderWidth = 1;
        _priceText.layer.cornerRadius = 5;
        _priceText.layer.masksToBounds = YES;
        _priceText.textAlignment = NSTextAlignmentCenter;
        _priceText.text = @"1";
    }
    return _priceText;
}
// 游戏角色
- (UILabel *)rolenameLabel{
    if (!_rolenameLabel) {
        _rolenameLabel = [UILabel new];
        _rolenameLabel.backgroundColor = [UIColor orangeColor];
        _rolenameLabel.textColor = [UIColor whiteColor];
        _rolenameLabel.layer.cornerRadius = 5;
        _rolenameLabel.layer.masksToBounds = YES;
        _rolenameLabel.font = [UIFont systemFontOfSize:14];
        _rolenameLabel.textAlignment = NSTextAlignmentCenter;
        _rolenameLabel.text = @"游戏角色:";
    }
    return _rolenameLabel;
}
- (UITextField *)rolenameText{
    if (!_rolenameText) {
        _rolenameText = [UITextField new];
        _rolenameText.backgroundColor = [UIColor whiteColor];
        _rolenameText.font = [UIFont systemFontOfSize:12];
        _rolenameText.clearButtonMode = UITextFieldViewModeWhileEditing;
        _rolenameText.placeholder = @"请输入游戏角色名";
        _rolenameText.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _rolenameText.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _rolenameText.layer.borderWidth = 1;
        _rolenameText.layer.cornerRadius = 5;
        _rolenameText.layer.masksToBounds = YES;
        _rolenameText.textAlignment = NSTextAlignmentCenter;
        _rolenameText.clearButtonMode = UITextFieldViewModeWhileEditing;
        _rolenameText.text = @"iOS测试账号";
    }
    return _rolenameText;
}
// 游戏区服
- (UILabel *)serviceLabel{
    if (!_serviceLabel) {
        _serviceLabel = [UILabel new];
        _serviceLabel.backgroundColor = [UIColor orangeColor];
        _serviceLabel.textColor = [UIColor whiteColor];
        _serviceLabel.layer.cornerRadius = 5;
        _serviceLabel.layer.masksToBounds = YES;
        _serviceLabel.font = [UIFont systemFontOfSize:14];
        _serviceLabel.textAlignment = NSTextAlignmentCenter;
        _serviceLabel.text = @"游戏区服:";
    }
    return _serviceLabel;
}
- (UITextField *)serviceText{
    if (!_serviceText) {
        _serviceText = [UITextField new];
        _serviceText.backgroundColor = [UIColor whiteColor];
        _serviceText.font = [UIFont systemFontOfSize:12];
        _serviceText.clearButtonMode = UITextFieldViewModeWhileEditing;
        _serviceText.placeholder = @"请输入游戏区服名";
        _serviceText.autocapitalizationType = UITextAutocapitalizationTypeNone;
        _serviceText.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _serviceText.layer.borderWidth = 1;
        _serviceText.layer.cornerRadius = 5;
        _serviceText.layer.masksToBounds = YES;
        _serviceText.textAlignment = NSTextAlignmentCenter;
        _serviceText.clearButtonMode = UITextFieldViewModeWhileEditing;
        _serviceText.text = @"测试115服";
    }
    return _serviceText;
}
// 用户中心
- (UIButton *)centerBtn{
    if (!_centerBtn) {
        _centerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _centerBtn.backgroundColor = [UIColor orangeColor];
        _centerBtn.layer.cornerRadius = 5;
        _centerBtn.tag = 200;
        [_centerBtn setTitle:@"用户中心" forState:UIControlStateNormal];
        [_centerBtn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
        [_centerBtn addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _centerBtn;
}
// 注销
- (UIButton *)logoutBtn{
    if (!_logoutBtn) {
        _logoutBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _logoutBtn.backgroundColor = [UIColor orangeColor];
        _logoutBtn.layer.cornerRadius = 5;
        _logoutBtn.tag = 300;
        [_logoutBtn setTitle:@"注销用户" forState:UIControlStateNormal];
        [_logoutBtn setTitleColor:[UIColor blackColor] forState:UIControlStateHighlighted];
        [_logoutBtn addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _logoutBtn;
}
#pragma mark - Getter
- (NSString *)payType
{
    return self.payTypeText.text;
}
- (NSString *)cpID{
    return self.cpIdText.text;
}
- (NSString *)price{
    return self.priceText.text;
}
- (NSString *)rolename
{
    return self.rolenameText.text;
}
- (NSString *)service
{
    return self.serviceText.text;
}

@end
